<template>
	<view class="early-wran page">
		<view class="date-group">
			<uni-datetime-picker v-model="datetimerange" type="datetimerange" rangeSeparator="至" @change="dateChange" />
		</view>
		<scroll-view  class="scroll-box" scroll-y="true">
			<u-time-line v-if="list.length">
				<u-time-line-item v-for="item in list" :key="item.alarmId">
					<!-- 此处没有自定义左边的内容，会默认显示一个点 -->
					<template v-slot:content>
						<view>
							<view class="u-order-desc" @click="openApp('com.mm.android.lc')">
								{{item.msgType === "smdHuman"?'检测到人形':'未知'}}
							</view>
							<view class="u-order-time">{{item.localDate}}</view>
							<image :src="item.thumbUrl" mode=""></image>
						</view>
					</template>
				</u-time-line-item>
			</u-time-line>
			<u-empty v-else text="暂无数据" mode="list"></u-empty>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				datetimerange: [],
				list: [],
			}
		},
		onLoad() {
			this.getImouToken()
		},
		methods: {
			// this.$u.vuex('vuex_archives', data)
			// uni.setStorageSync('imouData', {accessToken:''});
			getImouToken(timeArr) {
				const dateNowBegin = new Date().toLocaleDateString()
				const dateNowEnd = new Date(dateNowBegin).getTime() + 60 * 60 * 24 * 1000

				this.datetimerange = [new Date(dateNowBegin).getTime(), dateNowEnd]
				let beginTime = this.$u.timeFormat(dateNowBegin, 'yyyy-mm-dd hh:MM:ss')
				let endTime = this.$u.timeFormat(dateNowEnd, 'yyyy-mm-dd hh:MM:ss')
				if (timeArr) {
					beginTime = timeArr[0]
					endTime = timeArr[1]
				}

				this.$u.api.imou.getWarnList(beginTime, endTime, 30).then(res => {
					if (res.result.code == 0) {
						// console.log(JSON.stringify((res.result.data.alarms)));
						this.list = res.result.data.alarms
					}
				})
			},
			dateChange(e) {
				console.log(e);
				this.getImouToken(e)
			},
			openApp(name) {
				// #ifdef APP-PLUS
				const isApp = plus.runtime.isApplicationExist({
					pname: name
				});

				if (isApp) {
					plus.runtime.launchApplication({
						// pname: "com.sensopia.magicplan",
						// pname: "com.jideos.jnotes",
						pname: name,
					}, (e) => {
						console.log('error', e.message)
					}, );
				} else {
					console.log('App未安装~');
				}
				// #endif
			}
		}
	}
</script>

<style lang="scss" scoped>
	.scroll-box {
		height: calc(100vh - 80px);
		/* #ifdef H5 */
		height: calc(100vh - 44px - 85px);
		/* #endif */
	}
	.date-group {
		margin-bottom: 40upx;
	}

	.early-wran {
		padding: 40upx;
		background-color: #fff;
	}

	.u-time-axis {
		padding-left: 80upx;
	}

	.u-node {
		width: 44rpx;
		height: 44rpx;
		border-radius: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #d0d0d0;
	}

	.u-order-title {
		color: #333333;
		font-weight: bold;
		font-size: 32rpx;
	}

	.u-order-desc {
		color: rgb(150, 150, 150);
		font-size: 28rpx;
		margin-bottom: 6rpx;
	}

	.u-order-time {
		color: rgb(200, 200, 200);
		font-size: 26rpx;
	}
</style>
